import org.jcsp.lang.Alternative;
import org.jcsp.lang.AltingChannelInputInt;
import org.jcsp.lang.AltingChannelOutputInt;
import org.jcsp.lang.CSProcess;
import org.jcsp.lang.ChannelInputInt;
import org.jcsp.lang.ChannelOutputInt;
import org.jcsp.lang.Parallel;
import org.jcsp.plugNplay.ints.Delta2Int;
import org.jcsp.plugNplay.ints.PrefixInt;
import org.jcsp.plugNplay.ints.SuccessorInt;


class JcspPhil implements CSProcess { 
	int number;
	private ChannelInputInt in1  = null; 
	private ChannelInputInt in2  = null; 
	private ChannelOutputInt out1 = null; 
	private ChannelOutputInt out2= null; 
/*	
	public JcspPhil(int number,ChannelInputInt in1, 
	  ChannelInputInt in2, 
	  ChannelOutputInt out1, 
	  ChannelOutputInt out2) {
		
	    this.in1 = in1; 
		this.in2 = in2; 
		this.out1= out1; 
		this.out2= out2;
	
	}
*/	
/*	public JcspPhil(int i, ChannelInputInt in, ChannelInputInt in3,
			ChannelOutputInt out, ChannelOutputInt out3) {
		    this.number = i;
		    this.in1 = in; 
			this.in2 = in3; 
			this.out1= out; 
			this.out2= out3;
		// TODO Auto-generated constructor stub
	}
*/
	public JcspPhil(int i, AltingChannelInputInt in,
			AltingChannelInputInt in3, AltingChannelOutputInt out,
			AltingChannelOutputInt out3) {
	    this.number = i;
	    this.in1 = in; 
		this.in2 = in3; 
		this.out1= out; 
		this.out2= out3;
		// TODO Auto-generated constructor stub
	}

	public void run(){  // Server 
	/*  Alternative alt = new Alternative(in1); 
	  int index; 
	  while(true) { 
		index= alt.fairSelect(); 
		in[index].read(); 
		toService.write(0); 
		fromService.read(); 
		 out[index].write(1); 
		
	  } 
	   */
		System.out.println (number + "This version uses *symmetric* channels");
		
	      new Parallel (
	    	        new CSProcess[] {
	    	        		new PrefixInt ( number,in1, out1),
	    	        		new PrefixInt ( number+1,in2, out2),
	    	        		new Reciv(number+2, in1),
	    	        		new Reciv(number+3, in2)
	    	        }
	    	      ).run ();
	      System.out.println (number + "wyslano i odbieram");
	    //  System.out.println (in1.read());
	    //  System.out.println (in2.read());
	} 
}